package flc.ast.adapter;

import android.view.View;
import android.widget.ImageView;

import androidx.annotation.NonNull;

import com.blankj.utilcode.util.ImageUtils;
import com.blankj.utilcode.util.TimeUtils;
import com.bumptech.glide.Glide;
import com.chad.library.adapter.base.provider.BaseItemProvider;
import com.chad.library.adapter.base.viewholder.BaseViewHolder;

import flc.ast.R;
import stark.common.basic.adaptermutil.StkProviderMultiAdapter;
import stark.common.basic.adaptermutil.StkSingleSpanProvider;
import stark.common.basic.utils.MediaUtil;
import stark.common.basic.utils.TimeUtil;

public class AddDataAdapter extends StkProviderMultiAdapter<String> {

    public AddDataAdapter() {
        addItemProvider(new StkSingleSpanProvider<>(100));
        addItemProvider(new AddDataProvider());
    }

    private class AddDataProvider extends BaseItemProvider<String> {
        @Override
        public int getItemViewType() {
            return StkProviderMultiAdapter.TYPE_VIEW;
        }

        @Override
        public int getLayoutId() {
            return R.layout.item_add_data;
        }

        @Override
        public void convert(@NonNull BaseViewHolder baseViewHolder, String path) {
            if (baseViewHolder.getAdapterPosition() == 0) {
                baseViewHolder.getView(R.id.ivAddDataItemBg).setVisibility(View.GONE);
                baseViewHolder.setImageResource(R.id.ivAddDataItemImg, R.drawable.atianjiawenj2);
            } else {
                if (ImageUtils.isImage(path)) {
                    baseViewHolder.getView(R.id.ivAddDataItemBg).setVisibility(View.GONE);
                } else {
                    baseViewHolder.getView(R.id.ivAddDataItemBg).setVisibility(View.VISIBLE);
                    baseViewHolder.setText(R.id.tvAddDataItemDuration, TimeUtil.getMmss(MediaUtil.getDuration(path)));
                }
                Glide.with(getContext()).load(path)
                        .into((ImageView) baseViewHolder.getView(R.id.ivAddDataItemImg));
            }
        }
    }
}
